from langchain_core.tools import tool

try:
    from rag.boss_file.llm_response import HybridGuideSearch  # 若有
except Exception:
    HybridGuideSearch = None


@tool(description="知识检索：对问题进行混合检索并返回结果数量")
def KnowledgeSearch(query: str) -> str:
    if not HybridGuideSearch:
        return "RAG_DISABLED"
    try:
        hs = HybridGuideSearch()
        hs.setup(recreate=False)
        results = hs.hybrid_search(query=query, query_embedding=None, size=5)
        return f"HITS:{len(results)}"
    except Exception:
        return "RAG_ERROR"


def build_knowledge_tools():
    return [KnowledgeSearch]


